package com.iceGame;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.GLCommon;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;



public class MainMenuScreen implements Screen {
	
	OrthographicCamera guiCam;
	SpriteBatch batcher;

	Rectangle playBounds;
	Rectangle optionsBounds;
	Rectangle exitBounds;
	Vector3 touchPoint;
	Game game;
	public MainMenuScreen (Game game){
		this.game = game;
		int width = 800;
		int height = 480;
		batcher = new SpriteBatch();
		guiCam = new OrthographicCamera(width,height);		
		guiCam.position.set(width / 2, height / 2, 0);
		touchPoint = new Vector3();
		playBounds = new Rectangle(350,480-290,200,90);
		optionsBounds = new Rectangle(350,480-380,280,80);
		exitBounds = new Rectangle(350,480-460,185,75);
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub

	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}
	public void update(float deltaTime){
		if (Gdx.input.justTouched()) {
			guiCam.unproject(touchPoint.set(Gdx.input.getX(), Gdx.input.getY(), 0));
			
			if (OverlapTester.pointInRectangle(playBounds, touchPoint.x, touchPoint.y)){
				if (Settings.soundEnabled)
					Assets.buttonPressSound.play();
				game.setScreen(new LevelSelectionScreen(game));				
				this.dispose();
			}
			else if (OverlapTester.pointInRectangle(optionsBounds, touchPoint.x, touchPoint.y)){
				if (Settings.soundEnabled)
					Assets.buttonPressSound.play();
				game.setScreen(new OptionsScreen(game));
				this.dispose();
			}
			else if (OverlapTester.pointInRectangle(exitBounds, touchPoint.x, touchPoint.y)){
				if (Settings.soundEnabled)
					Assets.buttonPressSound.play();
				this.dispose();
				Gdx.app.exit();
			}

			
			
		}
	}
	@Override
	public void render(float deltaTime) {
		update(deltaTime);
		GLCommon gl = Gdx.gl;
		gl.glClearColor(1, 0, 0, 1);
		gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		guiCam.update();
		batcher.setProjectionMatrix(guiCam.combined);	
		batcher.disableBlending();
		batcher.begin();
		batcher.draw(Assets.mainMenuScreen, 0, 0, 800, 480);
		batcher.end();
	}

	@Override
	public void resize(int arg0, int arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void show() {
		// TODO Auto-generated method stub

	}

}
